package com.onec.service.customer.entity.merchant;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.onec.service.api.content.AesEntityContent;
import com.onec.service.api.enums.ProductEnum;
import com.onec.service.api.enums.StatusEnum;
import lombok.Data;
import org.hibernate.annotations.ColumnTransformer;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

/**
 * 代理商
 * 渠道信息。
 *
 * @author ONEC
 */
@Data
@Entity
@Table(name = "t_merchant_info")
public class MerchantInfo implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", unique = true)
    private Long id;

    @Column(name = "version", length = 8)
    @Version
    private Integer version;

    @Column(name = "agent_id", length = 16)
    private Long agentId;

    @Column(name = "code", length = 16, unique = true)
    private String code;

    /**
     * 敏感信息数据库中加解密存储.
     * mysql函数：CAST ：转为MySQL字符串》
     * AES_DECRYPT （解密）
     * AES_ENCRYPT（加密）
     */
    @Column(name = "name")
    @ColumnTransformer(
            forColumn = "name",
            read = AesEntityContent.AES_DECRYPT_NAME,
            write = AesEntityContent.AES_ENCRYPT_NAME
    )
    private String name;

    @Column(name = "product", length = 12)
    @Enumerated(value = EnumType.STRING)
    private ProductEnum product;

    @Column(name = "contacts", length = 32)
    private String contacts;

    @ColumnTransformer(
            forColumn = "phone",
            read = AesEntityContent.AES_DECRYPT_PHONE,
            write = AesEntityContent.AES_ENCRYPT_PHONE
    )
    @Column(name = "phone")
    private String phone;

    @Column(name = "out_code", length = 32, unique = true)
    private String outCode;

    @Column(name = "create_time")
    @CreatedDate
    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy-MM-dd HH:ss:mm", timezone = "GTM+8")
    private Date createTime;

    @Column(name = "update_time")
    @LastModifiedDate
    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy-MM-dd HH:ss:mm", timezone = "GTM+8")
    private Date updateTime;

    @Column(name = "creator", length = 32)
    private String creator;

    @Column(name = "remarks")
    private String remarks;

    @Column(name = "status", length = 12)
    @Enumerated(value = EnumType.STRING)
    private StatusEnum status;

    @ColumnTransformer(
            read = AesEntityContent.AES_DECRYPT_CARD_NO,
            write = AesEntityContent.AES_ENCRYPT_CARD_NO
    )
    @Column(name = "card_no")
    private String cardNo;


    @ColumnTransformer(
            read = AesEntityContent.AES_DECRYPT_ID_CARD,
            write = AesEntityContent.AES_ENCRYPT_ID_CARD
    )
    @Column(name = "id_card")
    private String idCard;

    /**
     * 商户地址
     */
    @Column(name = "address", length = 64)
    private String address;
    /**
     * 省
     */
    @Column(name = "province", length = 8)
    private String province;
    /**
     * 省
     */
    @Column(name = "city", length = 8)
    private String city;
    /**
     * 省
     */
    @Column(name = "country", length = 8)
    private String country;

}
